package com.candy.candyproduct.controller;

import com.candy.candycommon.utils.BeanConvertUtils;
import com.candy.candycommon.utils.HttpServletUtils;
import com.candy.candycommon.utils.ResultBean;
import com.candy.candyorderrpc.service.OrderService;
import com.candy.candyproduct.bean.EsQuestion;
import com.candy.candyproduct.service.EsQuestionService;
import com.candy.candyproductservice.dto.EsSearchDTO;
import com.candy.candyproductservice.vo.EsQuestionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author suYanLong
 * @date 2022年09月29日 13:36
 */
@Slf4j
@RestController
@RequestMapping("question")
public class QuestionController {

    @Resource
    EsQuestionService esQuestionService;

    @Resource
    OrderService orderService;

    @PostMapping("getList")
    public ResultBean getByOrderId(@RequestBody EsSearchDTO esSearchDTO) {

        String token = HttpServletUtils.getRequest().getHeader("token");
        log.info(" token = {}", token);

        orderService.getByOrderId(111l);

        List<EsQuestion> search = esQuestionService.search(esSearchDTO);
        log.info(" QuestionController -----------------> getList {}", esSearchDTO);
        try {
            Thread.sleep(0);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return ResultBean.ok(BeanConvertUtils.convertListTo(search, EsQuestionVO::new));
    }

}
